from UserList import UserList

from nest.path import Path
from nest.path.iterator import PathKey


class ParsedPath(UserList, Path):

    @classmethod
    def simplify(self, path):
        result = path
        if isinstance(path, list):
            if len(path) == 1 and isinstance(path[0], PathKey):
                result = path[0]
            else:
                result = ParsedPath(path)
        assert isinstance(result, (PathKey, ParsedPath))
        return result
